<?php
use Phalcon\Validation;
use Phalcon\Validation\Validator\PresenceOf;

class User extends \Phalcon\Mvc\Model {
    // const ERR_NAME_NOT_EMPTY = '用户名称不能为空';

    /**
     *
     * @var integer
     */
    public $id;

    /**
     *
     * @var string
     */
    public $username;

    /**
     *
     * @var string
     */
    public $password;

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */

    public function getSource() {
        return 'user';
    }

    public function beforeCreate() {
        // Set the creation date
      //  $this->created_at = date('Y-m-d H:i:s');
    }

    public function beforeUpdate() {
        $this->validate(new \Phalcon\Mvc\Model\Validator\StringLength([
                'field'          => 'password',
                'max'            => 16,
                'min'            => 6,
                'messageMaximum' => '已经超过做大字符16',
                'messageMinimum' => '最少6个字符',
            ]));
        return $this->validationHasFailed() != true;
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return User[]
     */
    public static function find($parameters = null) {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return User
     */
    public static function findFirst($parameters = null) {
        return parent::findFirst($parameters);
    }

}
